<template>
	<view class="myOrderBox pb10">

		<view class="orderTitle">
		<uv-tabs lineWidth="30" lineColor="#3F7865" :activeStyle="{
			color: '#3F7865',
			fontWeight: 'bold',
			transform: 'scale(1.05)'
		}" @change="changeOrder" :list="list"></uv-tabs>
			
		</view>
		<view class="mb10" style="height: 90rpx;">

		</view>
		<!-- <view class="cardBox" v-for="(item,index) in orderList" :key="index" @click="toMain(item)"> -->
		<view class="artItem plr16 pt15 pb20  mlr10 mb10 radius6 " v-for="(i,n) in orderList" :key="n"
			@click="toMain(i)">

			<view class="align-center justify-between  pb15 flex1 orderdesc">
				<text class="order">{{i.order_no}}</text>
				<text class="status">{{i.status_info}}</text>
				
			</view>
			<view class=" justify-between align-center mt15">
				<image :src="i.goods_img" mode=""></image>
				<view class="flex-col justify-between flex1" style="height: 173rpx;">
					<view class="title clamp2 mb5">
						{{i.goods_name}}
					</view>
					<view class="">
						<view class="stages">
							¥{{i.show_price}}
						</view>
						<view class="justify-between align-end">
							<text class="money">¥ {{i.order_amount_total}}</text>

						</view>
					</view>
					<view class="cancel" v-if="i.status=='1'" @click.stop="cancelOrder(i)">
						取消订单
					</view>
				</view>
			</view>
		</view>
		<!-- </view> -->
		<view class="" v-if="orderList.length==0">
			<uv-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png"></uv-empty>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				titleFlag: 1,
				orderList: [],

				page: 1,
				list: [{
						name: '全部',
						val: "1"
					},
					{
						name: '待审核',
						val: "6"
					},
					{
						name: '代付中',
						val: "2"
					},
					{
						name: '已取消',
						val: "5"
					},
					{
						name: '未通过',
						val: "11"
					},
					{
						name: '已违约',
						val: "4"
					},
					{
						name: '已完成',
						val: "3"
					},
					{
						name: '已审核',
						val: "12"
					},
				
				]


			};
		},
		onLoad(opt) {
		if(opt.type)	this.titleFlag=opt.type
			this.getOrder()
		},
		onShow() {
			// if (!uni.getStorageSync('logintoken')) {
			// 	uni.reLaunch({
			// 		url: '/pages/login/login'
			// 	})
			// 	return
			// }

		},
		onReachBottom() {
			if (this.orderList.length < this.total) {
				this.page++
				this.getOrder()
			}
		},
		methods: {
			changeOrder(val) {
				console.log(val)
				this.titleFlag = val.val
			
				this.page = 1
				this.orderList = []
				this.getOrder()
			
			},
			formateTime(data) {
				return this.$utils.formatDateTime(data)
			},
			unpaidBtn(type) {
				this.titleFlag = type
				this.page = 1
				this.orderList = []
				this.getOrder()
			},
			async getOrder() {
				uni.showLoading({
					title: '加载中'
				})
				let data = await this.$api.wanghongorderlist({
					page: this.page,
					type_status: this.titleFlag
				})
				uni.hideLoading()
				if (data.code == 1) {
					this.total = data.data.total
					this.orderList = [...this.orderList, ...data.data.rows]
				}

			},
			cancelOrder(i){
				let vm =this
					uni.showModal({
						content:'确定要取消该订单吗',
						success:function(res){
							if(res.confirm){
										
									vm.$api.ordercancel({id:i.id}).then(res=>{
										vm.$utils.msg('操作成功')
										vm.orderList=[]
										vm.page=1
										vm.getOrder()
									})
							}
						}
					})
			},
			toMain(item) {

				uni.navigateTo({
					url: '/pages/orderDetail/index?id=' + item.id+"&status="+item.status
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.myOrderBox {
		min-height: 100vh;
		position: relative;
		background-color: RGBA(245, 245, 245, 1);

		.orderTitle {
			width: 750rpx;
			height: 90rpx;
			background-color: #FFFFFF;
			display: flex;
			font-size: 32rpx;
			color: #444;
			position: fixed;
			top: 0;

			// border-bottom: 2rpx solid  rgba(151,151,151,0.062);
			.titleItem {
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				flex-basis: 0rpx;
				flex-grow: 1;
				font-weight: 500;
			}

			.active {
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				flex-basis: 0rpx;
				flex-grow: 1;
				color: #3F7865;
				position: relative;
				font-weight: 500;
			}

			.active::after {
				position: absolute;
				content: "";
				width: 49rpx;
				height: 8rpx;
				background: #3F7865;
				border-radius: 4rpx;
				bottom: 0rpx;
				left: 50%;
				transform: translateX(-50%);

			}
		}

	}

	.submitPz {
		width: 165rpx;
		height: 54rpx;
		background: #434343;
		border-radius: 6rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 54rpx;
	}

	.artItem {

		background-color: #fff;
		font-size: 28rpx;
		color: #999999;

		image {
			width: 237rpx;
			height: 173rpx;
			border-radius: 8rpx;
			margin-right: 26rpx;
		}

		.title {
			font-weight: bold;
			font-size: 30rpx;
			color: #222222;
		}

		.orderdesc {
			border-bottom: 1rpx solid #EFEFEF;
		}

		.stages {
			border-radius: 5rpx;
			border: 1px solid #3F7865;
			color: #3F7865;
			font-size: 22rpx;
			display: inline-block;
			line-height: 22rpx;
			padding: 5rpx 8rpx;
		}

		.money {
			font-weight: 500;
			font-size: 34rpx;
			color: #333333;
		}

		.cancel {
			width: 150rpx;
			height: 52rpx;
			background: #3F7865;
			border-radius: 26rpx;
			font-weight: 400;
			font-size: 24rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 52rpx;
			margin-left: 200rpx;
		}
	}
</style>